﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolCode.Linq;
using CoolCode.Entities;
using CoolCode.Web.UI.Views;

namespace CoolCode.Web.UI.Controls
{
    public partial class CheckProductList : Partial<List<Inspection>>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            handleEvents();
        }

        protected void handleEvents()
        {
            GridViewHelper.HighlightCriterion(gvMaster);
            gvMaster.HandleSelectAll("chkSelectAll", "chkSelected");
        }

        public override void DataBind()
        {
            //base.DataBind();
            BindData_Master();
        }

        private void BindData_Master()
        {
            gvMaster.DataSource = Model;
            gvMaster.DataBind();
        }

        public List<string> GetSelections()
        {
            List<string> selected = gvMaster.GetSelections<string>("chkSelected", (int)InspectionColumn.ProductID);
            return selected;

            //List<string> selected = new List<string>();
            //foreach (GridViewRow gvr in gvMaster.Rows)
            //{
            //    CheckBox chk = gvr.FindControl("chkSelected") as CheckBox;
            //    if (chk != null)
            //    {
            //        if (chk.Checked)
            //        { //gvMaster.GetKey<int>(gvr.RowIndex )
            //            string key = gvr.Cells[(int)InspectionColumn.ProductID].Text;
            //            selected.Add(key);
            //        }
            //    }
            //}
            //return selected;
        }

        public void SelectAll()
        {
            gvMaster.SelectAll("chkSelected");
            //selectHelper(true);
        }

        //private void selectHelper(bool checkflag)
        //{
        //    foreach (GridViewRow gvr in gvMaster.Rows)
        //    {
        //        CheckBox chk = gvr.FindControl("chkSelected") as CheckBox;
        //        if (chk != null)
        //        {
        //            chk.Checked = checkflag;
        //        }
        //    }
        //}

    }



}